#! /bin/bash

rep_cv="./CV etudiants/"
rep_html="./CV etudiants HTML"
xslt_cv="CV.xsl"
cmd="sabcmd"

mkdir -p "$rep_html"

# Génération des CV HTML
for i in `ls "$rep_cv"`; do
        if [ `echo $i | sed "s/.*\.//g"` = "xml" ]
        then
                nom=`echo $i | sed "s/xml/html/"`
                $cmd "$xslt_cv" "$rep_cv/$i" > "$rep_html/$nom"
        fi
done

$cmd Competences.xsl Competences.xml > "$rep_html/Competences.html"
$cmd personnes.xsl personnes.xml > "$rep_html/personnes.html"

nbComp=`grep idC Competences.xml | tail -n 1 | cut -d "\"" -f 2`

for ((i = 1; i <= $nbComp; i += 1))
do
	$cmd Competences_Pers.xsl personnes.xml \$idC=$i > "$rep_html/personnes-$i.html"
done

$cmd personnes.xslt personnes.xml>tmp.fo
fop -fo tmp.fo -pdf sortie.pdf
